﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.ModelBinding;
using System.Windows.Input;
using Brutalmimi.Applicaiton.Share.Events;
using Brutalmimi.Applicaiton.Share.Models;
using Brutalmimi.Applicaiton.Share.Prism;
using Brutalmimi.Core.Ioc;
using Prism.Commands;
using Prism.Events;
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Regions;

namespace Shell.ViewModels
{
    internal class MainWindowViewModel : BindableBase
    {

        public MainWindowViewModel(IModuleManager moduleManager, IRegionManager regionManager)
        {
            LoadedCommand = new DelegateCommand(MainWindowLoaded);
        }
        public ICommand LoadedCommand { get; set; } 
        

        private string _title ="Scada";
        public string Title {
            get { return _title; }
            set { Title = value;RaisePropertyChanged(); }
        }
        public void MainWindowLoaded()
        {
            PrismProvider.ModuleManager.LoadModule(ModuleNames.ApplicationLoginModule);
            PrismProvider.RegionManager.RequestNavigate(RegionNames.MainRegion, ViewNames.LoginView);
            PrismProvider.EventAggregator.GetEvent<LoginSuccessEvent>().Subscribe(OnLoginSucceeded,ThreadOption.UIThread);
        }

        private void OnLoginSucceeded(CurrentUser user)
        {
            PrismProvider.ModuleManager.LoadModule(ModuleNames.ApplicationLoginModule);
            PrismProvider.RegionManager.RequestNavigate(RegionNames.MainRegion, ViewNames.MainView);
        }


    }
}
